package com.example.selfcontrol.controller;


import com.example.selfcontrol.config.Response;
import com.example.selfcontrol.entity.Article;
import com.example.selfcontrol.entity.resp.StarInfo;
import com.example.selfcontrol.service.StarOptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/star")
@Api(value = "收藏视图")
public class StarOptController {
    @Autowired
    private StarOptService starOptService ;

    @GetMapping("/add")
    @ApiOperation("收藏")
    public Response ClickStar(int articleId , int userId) {
        return starOptService.ClickStar(articleId,userId) ;
    }

    @GetMapping("/info")
    @ApiOperation("该文章是否收藏 | 收藏数")
    public StarInfo  getStarInfo(int articleId, int userId) {
        return starOptService.getStarInfo(articleId,userId) ;
    }


    @GetMapping("/count")
    @ApiOperation("收藏数量")
    public int CountStar(Long articleId) {   return starOptService.CountStar(articleId) ;  }

    @GetMapping("/personal")
    @ApiOperation("分页获取个人的收藏文章")
    public List<Article> UserStar(int userId , int pageNum , int pageSize) { return  starOptService.UserStar(userId,pageNum,pageSize) ; }

    @GetMapping("/personal/count")
    @ApiOperation("个人收藏数")
    public int personalStarCount(int userId) { return starOptService.personalStarCount(userId) ; }

    @GetMapping("/isStar")
    @ApiOperation("用户是否收藏")
    public boolean isUserStar(int userId , Long articleId) { return starOptService.isUserStar(userId,articleId) ; }
}
